﻿using LitJson;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace TableCore.Plugin
{
    public class HashFormatter : IGenFormatter, IGenCmdInitializer
    {
        public bool ignoreCase = false;
        readonly Regex num_pattern = new Regex(@"^(\-|\+)?\d+$");

        public IExportData ExportData(GTFile.Content content, string data, string cellName, string comment)
        {
            return null;
        }

        public JsonData Format(GTFile.Content content, string input, string cellName, string comment)
        {
            if (num_pattern.IsMatch(input))
                return int.Parse(input);
            if (ignoreCase)
                return StringUtil.IgnoreCaseToHash(input);
            else
                return StringUtil.ToHash(input);
        }

        public void Init(GTType type, Dictionary<string, string> args, string content)
        {
            string v;
            if (args.TryGetValue("ignore_case", out v))
                ignoreCase = StringUtil.EqualIgnoreCase(v, "true");
            else
                ignoreCase = type.Name == type.Name.ToLower();
        }

        public bool IsValid(string data)
        {
            return true;
        }

    }
}
